﻿
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QServices.Services
{
    public class QMainService
    {

        private static Lazy<string> dbConnectionString = new Lazy<string>(() =>
        {
            if(!string.IsNullOrWhiteSpace( AppRuntime.DbConnectionString))return AppRuntime.DbConnectionString;
           var conn= ConfigurationManager.AppSettings.Get("ConnectionString");         
            return conn;
        });

        private static Lazy<string> mysqlconnectionstring = new Lazy<string>(() =>
        {
			if (!string.IsNullOrWhiteSpace(AppRuntime.MysqlDbConnectionString)) return AppRuntime.MysqlDbConnectionString;
			var conn = ConfigurationManager.AppSettings.Get("mysql");
			return conn;
		});
		private static Lazy<string> mysqlversion = new Lazy<string>(() =>
		{
			if (!string.IsNullOrWhiteSpace(AppRuntime.MysqlVersionStr)) return AppRuntime.MysqlVersionStr;
			var conn = ConfigurationManager.AppSettings.Get("mysqlversion");
			return conn;
		});
		protected SqlServerDbContext CreateDbContext()
        {
            var db=new SqlServerDbContext(dbConnectionString.Value);
            return db;
        }

        protected MysqlDbContext CreateMySqlDbContext()
        {
            var db=new MysqlDbContext(mysqlconnectionstring.Value);
            return db;
        }
        protected SqlServerDbContext CreateSqlserverDbContext()
        {
			var db = new SqlServerDbContext(dbConnectionString.Value);
			return db;
		}

    }
}
